package leetcode_401_500;

import java.util.Set;

public class LeeCode_463 {
    public static void main(String[] args) {
        System.out.println(islandPerimeter(new int[][]{{1, 1}, {1, 1}}));
    }
    private static int islandPerimeter(int[][] grid) {
        int m = grid.length;
        int n = grid[0].length;
        int count = 0;
        int piff = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (grid[i][j] == 1) {
                    count++;
                    if (j + 1 < n && grid[i][j + 1] == 1){
                        piff++;
                    }
                    if (i + 1 < m && grid[i + 1][j] == 1){
                        piff++;
                    }
                }
            }
        }
        return count * 4 - piff * 2;
    }
}
